package cn.adley.hdfs.client;

import java.util.Random;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import cn.adley.hdfs.client.service.HDFSApi;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@SpringBootApplication
public class App {

    public static void main(String[] args) {
        log.info("args = {}, {}", args.length, args);
        ApplicationContext context = SpringApplication.run(App.class, args);
        try {
            switch(args[0]) {
            case "-w":
                HDFSApi hdfsApi = context.getBean(HDFSApi.class);
                var c = Integer.valueOf(args[4]);
                log.info("产生[{}]条数据", c);
                for (int i = 0 ; i< c; i++) {
                    var j = new Random();
                    hdfsApi.appendToHDFSFile(args[1], args[2], args[3]+j.nextInt(c));
                }
                break;
            }
        } catch(Exception e) {
            log.error("运行异常",e);
        }
    }
}
